<?php

namespace app\api\controller;

use app\api\model\PictureModel;
use think\Controller;

class Picture extends Controller {
    function picturelist() {
        $model = new pictureModel();
        $result = $model->picturelist();
        return json($result);
    }

    function picturedetail() {
        $pictureid = input('get.pictureid');
        $model = new PictureModel();
        $result = $model->picturedetail($pictureid);
        return json($result);
    }

    function reply() {
        $userid = input('get.userid');
        $pictureid = input('get.pictureid');
        $content = input('get.content');

        $model = new PictureModel();
        $result = $model->reply($userid, $pictureid, $content);
        return json($result);
    }

    function issuepicture() {
        $file = request()->file('aFile');
        $userid = input('userid');
        $intro = input('intro');
        $picname = input('picturename');
        $date =  date('Y-m-d h:i:s', time());
        if ($file) {
            $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
            if ($info) {
                $model = new PictureModel();
                $result = $model->issuepicture($userid,$picname,$intro,$date, $info->getSaveName());
              //  return json($result);
                return json(['msg' => "成功",'success'=>$result]);
            } else {
                return json(['msg' => $file->getError(),'success'=>'-1']);
            }
        }else{
            return json(['msg' => '无图片','success'=>'-1']);
        }
    }

    function myPicture(){
        $userid = input('get.userid');
        $model = new PictureModel();
        $result = $model->myPicture($userid);
        return json($result);
    }

    function deleteMyPicture(){
        $pictureid = input('get.pictureid');
        $model = new PictureModel();
        $result = $model->deleteMyPicture($pictureid);
        if ($result){
            return json(['msg'=>"成功",'success'=>$result]);
        }else{
            return json(['msg'=>'失败','success'=>'-1']);
        }


    }

}